<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="css/Global2.css">
    <link rel="stylesheet" href="css/style2.css">
    <title>疑惑解答</title>
    <style type="text/css">
    .problem {
        margin-top: 1rem;
    }
    .psearch {
        display: flex;
    }
    .psearch .modal-btn {
        width: 4rem;
        padding: 0;
        margin: 0;
        margin-left: 1rem;
        line-height: 2rem;
        text-align: center;
    }
    </style>
</head>

<body>
    <img src="img/easyloan.jpg" style="width: 100%;">
    <div class="problem">
        <div class="pleft">
            <div class="psearch">
                <input id="queryInput" type="text" class="col-16 form-input f14" placeholder="输入关键字查找问题">
                <a href="##" class="modal-btn btn-blue" onclick="querySelect()">查询</a>
            </div>
            <div class="mt-15">
                <div id="gQuestion" class="psort"></div>
                <div class="pcontent mb-30">
                    <div>
                        <ul id="gongyi">
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 翻页 -->
    <script src="js/jquery-3.5.1.js"></script>
    <script src="js/requestb.js"></script>
    <script src="js/all.js"></script>
    <script type="text/javascript">
    $(function() {
        //分页
        var pager = new PageList("pageDIV", {
            curPage: '1',
            totalCount: '10',
            pageRows: 1,
            callback: callbackFuc
        });
        //pager.init();
        // getTypeList()
        loadMoreData()
        getGongList()

    });

    function callbackFuc(curpage) {
        changePage(curpage);
    }
    </script>
    <script src="js/page.js"></script>
    <script>
    var baseUrl = baseUrl1()
    var pages = 2,
        size = 4,
        currentPage = 1,
        arr = [1, 2, 3, 4, 5, 6],
        index = 0,
        type = 1,
        cur = 1

    function getTypeList() {
        var url = baseUrl + 'mini/knowledge/list/0/14'
        wxAjax(url, "get", {}, function(res) {
            if (res.code == 200) {
                var data = res.data.records;
                var dataList = data.slice(7, 13)
                if (dataList.length) {
                    dataList.forEach((item, i) => {
                        var div = '<a href="##" class="' + (i == 0 ? 'text-red' : '') + '" typeId="' + item.knowledgeTypeId + '"><img src="img/gongchan_0' + (i + 1) + '.svg" style="width:1rem;margin-right:.2rem;">' + item.knowledgeTypeName + '</a>'
                        $('#gQuestion').append(div)
                    })
                }
            }
        }, function(res) {
            console.log(res); //请求失败
        })
        detail({
            knowledgeTypeId: 1,
        })
    }

    function getGongList() {
        var url = baseUrl + 'mini/knowledge/list/0/6'
        wxAjax(url, "get", {}, function(res) {
            if (res.code == 200) {
                var dataList = res.data.records;
                if (dataList.length) {
                    dataList.forEach((item, i) => {
                        var div = '<a href="##" class="' + (i == 0 ? 'text-red' : '') + '" typeId="' + item.knowledgeTypeId + '"><img src="img/gongchan_0' + (i + 1) + '.svg" style="width:1rem;margin-right:.2rem;">' + item.knowledgeTypeName + '</a>'
                        $('#gQuestion').append(div)
                    })
                }
            }
        }, function(res) {
            console.log(res); //请求失败
        })
        detail({
            knowledgeTypeId: 1,
        })
    }

    function detail(data) {
        var url1 = baseUrl + 'mini/knowledge/getKnowledgeList?page=0&size=20'
        wxAjax(url1, "get", data, function(res) {
            if (res.code == 200) {
                var dataList = res.data.records;
                if (dataList.length) {
                    dataList.forEach((item, i) => {
                        var div = pinSelect(item, i)
                        $('#gongyi').append(div)
                    })
                }
            }
        }, function(res) {
            console.log(res); //请求失败
        })
    }

    function querySelect() {
        var title = $('#queryInput').val()
        $("#zhihuan").empty();
        $("#gongyi").empty();
        detail({
            title
        })
    }

    function loadMoreData() {
        var url = baseUrl + 'mini/knowledge/getKnowledgeCaredList?knowledgeAttr=1'
        var data = {
            knowledgeTypeId: 9,
            page: currentPage,
            size: size
        }
        wxAjax(url, "get", data, function(res) {
            if (res.code == 200) {
                var dataList = res.data.records;
                pages = res.data.pages;
                if (dataList.length) {
                    dataList.forEach((item, i) => {
                        var div = '<li><a href="##" target="_self">' + item.knowledgeTitle + '</a></li>'
                        $('#like').append(div)
                    })
                }
            }
        }, function(res) {
            console.log(res); //请求失败
        })
    }

    function pinSelect(item, i) {
        var div = '<li class="pitem">' +
            '<h5 class=""><a href="##" target="_self">' + item.knowledgeTitle + '</a></h5>' +
            '<span class="f14 g9 mb-10">' + item.knowledgeContent + '</span></li>'
        return div
    }
    // $('.pnav').find('span').click(function() {
    //     $(this).addClass('active').siblings().removeClass('active');
    //     $('.pcontent>div').eq($(this).index()).show().siblings('div').hide();
    //     if ($('#zQuestion').hasClass('hide')) {
    //         $('#zQuestion').removeClass('hide')
    //         $('#gQuestion').addClass('hide')
    //         type = 0
    //         detail({
    //             knowledgeTypeId: 9,
    //         })
    //     } else {
    //         $('#zQuestion').addClass('hide')
    //         $('#gQuestion').removeClass('hide')
    //         type = 1
    //         detail({
    //             knowledgeTypeId: 1,
    //         })
    //     }

    // });

    $('.psort').on("click", "a", function(e) {
        $(this).siblings().removeClass('text-red');
        $(this).addClass("text-red")
        $("#zhihuan").empty();
        $("#gongyi").empty();
        detail({
            knowledgeTypeId: $(this).attr("typeId")
        })
    });
    </script>
</body>
<style>
.pitem p {
    margin-bottom: 10px;
}
</style>

</html>